#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;

class Solution{
    public:
    string ans1(string path){
        stack<string> stk;
        vector<string> sub_path;
        int p = 0, len = path.size();
        while(p < len){
            string temp = "";
            while(p < len){
                if(path[p] == '/'){
                    break;
                }
                temp = temp + path[p];
                p++;
            }
            if(temp.size()){
                sub_path.push_back(temp);
            }
            p++;
        }

        for(int i = 0; i != sub_path.size(); i++){
            if(stk.empty() && sub_path[i] != ".." && sub_path[i] != "."){
                stk.push(sub_path[i]);
            }else{
                if(sub_path[i] == "."){
                    continue;
                }
                else if(sub_path[i] == ".."){
                    if(stk.empty()){
                        continue;
                    }
                    stk.pop();
                }
                else{
                    stk.push(sub_path[i]);
                }
            }
        }
        string ret = "";
        int l = stk.size();
        if(l != 0){
            for(int i = 0; i != l; i++){
                ret = "/" + stk.top() + ret;
                stk.pop();
            }
        }else{
            ret = "/";
        }
        return ret;
    }

    

};

void test1(){
    Solution s;
    string str = "/home/user/Documents/../Pictures";
    string ret = s.ans1(str);
    cout << ret << endl;
}

void test2(){
    Solution s;
    string str = "/.../a/../b/c/../d/./";
    string ret = s.ans1(str);
    cout << ret << endl;
}

void test3(){
    Solution s;
    string str = "/../";
    string ret = s.ans1(str);
    cout << ret << endl;
}

void test4(){
    Solution s;
    string str = "/home//foo/";
    string ret = s.ans1(str);
    cout << ret << endl;
}


int main(void){
    test1();
    test2();
    test3();
    test4();

    return 0;
}